package com.PAT.practice03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/02/18/23:42
 * @Description:
 * @Target:
 */
public class 火星数字 {
/*
* tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。 对应着几个13
* jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。  1 -12
* tret 0
*
* */


    public static void main(String[] args) {
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
//        String s = bufferedReader.readLine();

        Scanner in = new Scanner(System.in);
        String ss1 = in.nextLine();
        String[] strings = new String[Integer.valueOf(ss1)];
        for (int i = 0; i < Integer.valueOf(ss1); i++) {
            strings[i] = in.nextLine();

        }
        for (String string : strings) {
            if ("0".equals(string)){
                System.out.println("tret");
            }else if ("tret".equals(string)){
                System.out.println("0");
            }else {
                System.out.println(process(string));
            }

        }


    }

    // 进来数字处理，进来字母处理
    static String process(String ss){
        String returnString = "";
        // s1是低位的0-12，遇到13进高位s2  "tret",
        String[] s1 = new String[]{"jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
        // 高位s2,下标0-11
        String[] s2= new String[]{"tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};

        if (Character.isDigit(ss.charAt(0))){
            Integer integer = Integer.valueOf(ss);
            int yuShu = integer%13;
            int s2Int = integer/13;
            if (s2Int>0){
                if (yuShu!=0){
                  returnString += s2[s2Int-1]+" ";
                }else {
                    returnString += s2[s2Int-1];
                }
            }
            if (yuShu>0) {
                returnString += s1[yuShu-1];
            }

        }else {
            String[] s = ss.split(" ");
            int sum = 0;
            if (s.length==2){
                for (int i = 0; i < s1.length; i++) {

                    // 记录s2的值
                    if (s[0].equals(s2[i])){
                        sum+=(i+1)*13;
                    }
                    // 记录s1的值
                    if (s[1].equals(s1[i])){
                        sum+=(i+1);
                    }
                }
            }else {
                for (int i = 0; i < s1.length; i++) {

                    // 记录s2的值
                    if (ss.equals(s2[i])){
                        sum+=(i+1)*13;
                    }
                    // 记录s1的值
                    if (ss.equals(s1[i])){
                        sum+=(i+1);
                    }
                }
            }

            returnString = sum+"";
        }

        return returnString;
    }
}
